
	$(document).ready(function() {
		selectDataList(1,"","","","");
	});

	function selectDataList(pageNo,time,name,phoneNumber,status) {
		$("#thislist").html("");
		$.ajax({
			url: urlcore + "/api/evaluation/findByPage?gmtDateTime=" + time + "&goodsName=" + name + "&phone=" + phoneNumber + "&currentPage=" + pageNo+"&status="+status,
			type: "get",
			dataType: 'json',
			async:'false',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
        	if(data.success == true) {
        			var type=data.data.roleType;
					$.each(data.data.page.list, function(i, n) {
						var id = n.id;
						var auditor="未知",admin="未知";
						if(n.auditor!=null && type!=5){
							auditor=n.auditor.name;
						}
						if(n.admin!=null && type!=1){
							admin=n.admin.name;
						}
						//var total_money="未使用";
						//if(n.userCoupon!=null){
						//	total_money="减免"+n.userCoupon.totalMoney;
						//}
					 	//var auditorstatus='none',adminstatus="none";
				       	//if(type==0 || type==1 ){
						//	adminstatus='';
				       	//}
						//if(type==0 || type==5){
						//	auditorstatus="";
						//}
				       	var upttime="未打款";
				       	if(n.status=='已打款' || n.status=='已完结' || n.status=='待出款'){
				       		upttime=n.uptDatetime;
				       	}
						var thislist =
							'<tr class="footable-even" style="display: table-row;">' +
							'<td class="footable-visible">' + n.user.phone + '</td>' +
							'<td class="footable-visible">' + n.user.realName + '</td>' +
							'<td class="footable-visible">' + n.name + '</td>' +
							'<td class="footable-visible">' + n.rentMoney + '</td>' +
							'<td class="footable-visible">' + (n.rentMoney*n.paramSetting.cashPledge).toFixed(2) + '</td>' +
							'<td class="footable-visible">' + n.status + '</td>' +
							'<td class="footable-visible">' + n.paramSetting.assessMoney + '</td>' +
							//'<td class="footable-visible">' + total_money + '</td>' +
							'<td class="footable-visible">' + n.payMoney + '</td>' +
							'<td class="footable-visible">' + n.finalMoney + '</td>' +
							'<td class="footable-visible">' + n.gmtDatetime + '</td>' +
							//'<td class="footable-visible">' + upttime + '</td>' +
							'<td class="footable-visible">' + auditor + '</td>' +
							//'<td class="footable-visible">' + admin + '</td>' +
							'<td class="footable-visible footable-last-column">'
						    if(n.status=='待审核'){
								thislist += '<a  class="btn btn-info btn-xs" style="display:;"  onclick="checkEvaluaion('+n.id+',1)" >通过</a>&nbsp;'+
											'<a  class="btn btn-danger btn-xs" style="display:;" onclick="checkEvaluaion('+n.id+',2)">拒绝</a>&nbsp;'+
											'<a  class="btn btn-info btn-xs" style="display:;"  onclick="loansReport('+n.id+')" >贷前报告</a>&nbsp;'+
											'<a  class="btn btn-success btn-xs" style="display:;" href="https://new-my.udcredit.com/#/login" >有盾报告</a>&nbsp;'+
											'<a  class="btn btn-success btn-xs" style="display:;" href="personMessage.html?userId='+n.userId+'" >认证信息</a>&nbsp;';
							}else if(n.status=='待打款' || n.status=='打款失败'){

							}
					thislist +=			'</td>' +
							'</tr>';
						$('#thislist').append(thislist);
						$('#thiscount').html(data.data.page.total);
						
					});
					$("#pager").pager({
						pagenumber: pageNo,
						pagecount: data.data.page.pages,
						totalcount: data.data.page.total,
						buttonClickCallback: PageClick
					});
				}else if (data.code == 'OVERTIME'){
					var thisUrl = window.location.href;
					if (thisUrl.indexOf('login.html') <= -1) {
						top.window.location.href="login.html";
					}
				}

			},
			error: function() {
				alert("服务器异常");
			}
		});
	}
	
	PageClick = function(pageclickednumber) {
		var phoneNumber=$('#phoneNumber').val().trim();
		var userName=$('#userName').val().trim();
		var time=$('#applyTime').val().trim();
		var status=$('#status').val();
		selectDataList(pageclickednumber,time,userName,phoneNumber,status);
	}


/**
 * 审核通过拒绝
 */
function checkEvaluaion(id,type){
	$.ajax({
		url: urlcore + "/api/evaluation/checkEvaluaion?id=" + id + "&type=" + type,
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				window.location.reload();
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});

}


/**
 * 搜索
 */
function searchList(){
	
	var phoneNumber=$('#phoneNumber').val().trim();
	var userName=$('#userName').val().trim();
	var time=$('#applyTime').val().trim();
	var status=$('#status').val();
	selectDataList(1,time,userName,phoneNumber,status);
	
}

/**
  打款
 */
function paymoney(id,userId){
	swal({
			title: "打款金额",
			text: "请填写打款金额并确认",
			type: "input",
			showCancelButton: true,
			closeOnConfirm: false,
			animation: "slide-from-top",
			inputPlaceholder: "请保留两位小数"
		}, function(inputValue) {
			if (inputValue === false)
				return false;
			if (inputValue === "" || inputValue.indexOf(".")==-1) {
				swal.showInputError("打款金额不合法");
				return false
			}
			
		$.ajax({
			url: urlcore + "/api/lianlian/linalianPay?evaluationId=" + id+"&money="+encode64(inputValue)+"&userId="+userId,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
			  if(data.success == true){
		          window.location.reload();
				}else{
					swal("OMG!", data.msg, "error");
				}
			 }
	     });
	});
}
	
	/**
	 * 拒绝打款
	 * 
	 */
	function refused(id){
		swal({
			title: "拒绝原因",
			text: "请填写拒绝原因",
			type: "input",
			showCancelButton: true,
			closeOnConfirm: false,
			animation: "slide-from-top",
			inputPlaceholder: "拒绝原因"
		}, function(inputValue) {
			if (inputValue === false)
				return false;
			if (inputValue === "") {
				swal.showInputError("请输入!");
				return false
			}
			
		$.ajax({
			url: urlcore + "/api/evaluation/refused?id=" + id+"&refuseReason="+inputValue,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
			  if(data.success == true){
		          window.location.reload();
				}else{
					swal("OMG!", data.msg, "error");
				}
			 }
	     });
	});
}

function loansReport(evaluationId) {
	$.ajax({
		url: urlcore + "/api/tongdunAudit/selectTongdunAuditById?id=" + evaluationId,
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var content = '[' + data.data.content.toString()+ ']';
				$.showReport(jQuery.parseJSON(content))
				var score = $("#result-score").text();
//				var resultScore="";
//				if(Number(score)>10){
//					resultScore = Number(score);
//				}else{
//					resultScore = Number(score) - 10;
//				}
				$("#result-score").text(score);
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
}


//导出表格
function excal() {
	var phoneNumber=$('#phoneNumber').val();
	var userName=$('#userName').val();
	var time=$('#applyTime').val();
	var status=$('#status').val();
	$.ajax({
		url: urlcore + "/api/evaluation/makeExcle?gmtDatetime=" + time + "&goodsName=" + userName + "&phone=" + phoneNumber + "&status="+status,
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var url1 =  data.data.toString().slice(4);
				location.href="https"+url1;
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
}
